<?php
namespace Home\Model;
use Think\Model;
class ClassModel extends Model {
    /**
     * 获取课程列表
     * @param   $where
     * @param   $page
     * @return Ambigous <\Think\mixed, boolean, string, NULL, mixed, multitype:, unknown, object>
     */
    public function getClassListByPage($where,$page){
        $class=D('class');
        $classList=$class->alias('c')->join("course_cate cate ON  c.cateid=cate.id","left")
        ->join("course_user  u  ON c.uid=u.id")
        ->field("c.id,c.title,cate.name catename,u.nickname")
        ->where($where)->order('c.id desc')->page($page)->select();
        return $classList;
    }
    
    public function getclassCount($where){
        $class=D('class');
        $count=$class->where($where)->count();
        return $count;
    }
    
    public function getclassList($where){
        $class=D('class');
        $classList=$class->alias('c')->join("course_user u on c.uid=u.id ","left")->
        field("c.*,u.nickname,u.headimgurl,u.introduce")->where($where)->order("id desc")->select();
        return $classList;
    }
    
    /**
     * 获取单个课程 
     * @param   $where
     * @return Ambigous <\Think\mixed, boolean, NULL, multitype:, mixed, unknown, string, object>
     */
    public function getClassItem($where){
        $class=D('class');
        $classItem=$class->where($where)->find();
        return $classItem;
    }
    /**
     * 添加课程
     */
    public function addClass($data){
        $class=D('class');
        $result=$class->add($data);
        return $result;
    }
    /**
     * 修改课程
     * @param   $where
     * @param   $data
     * @return Ambigous <boolean, unknown>
     */
    public function upClass($where,$data){
        $class=D('class');
        $result=$class->where($where)->save($data);
        return $result;
    }
    /**
     * 删除课程
     */
    public function delClass($where){
        $class=D('class');
        $result=$class->where($where)->delete();
        return $result;
    }
	
}